﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BHXH.Core.IService;
using FX.Core;
using CRM.Admin;
using BHXH.Core.Domain;
using NHibernate.Cfg;
using NHibernate;
using System.Resources;


namespace BHXH.Frm.FrmUserControl
{
    public partial class _01_DKBB : UserControl
    {
        private int ID = 4;
        private string IDref = "9";
        hs_01DKBB_ms ThongTinDangKi = new hs_01DKBB_ms();
        private readonly Ihs_01DKBB_msService _ttdkbh_dkbb01msSrv;
        public _01_DKBB()
        {
            InitializeComponent();
            _ttdkbh_dkbb01msSrv = IoC.Resolve<Ihs_01DKBB_msService>();
             this.Focus();
             
        }

        private void _01_DKBB_Load(object sender, EventArgs e)
        {
            Load_Data(ID, IDref);
        }

        public void Load_Data(int ID, string IDref) 
        {
            ThongTinDangKi = _ttdkbh_dkbb01msSrv.Load_DangKi_BaoHiem(ID, IDref);
            lblID.Text = ThongTinDangKi.ID.ToString();
            this.txtBHXH.Text = ThongTinDangKi.KinhGui;
            this.txtTenDonVi.Text = ThongTinDangKi.TenDV;
            this.txtDiaChi.Text = ThongTinDangKi.DiaChi;
            this.txtDienThoai.Text = ThongTinDangKi.DienThoai;
            this.txtDiaChiEmail.Text = ThongTinDangKi.Email;
            this.txtFax.Text = ThongTinDangKi.Fax;
            this.txtGiayPhepKDSo.Text = ThongTinDangKi.CNDK_So;
            //Ngay
            this.txtDoDonViCap.Text = ThongTinDangKi.CNDK_Do;
            this.txtLoaiHinhDonVi.Text = ThongTinDangKi.LHDV;
            this.txtMaSoThue.Text = ThongTinDangKi.MST;
            this.txtTaiKhoanSo.Text = ThongTinDangKi.TK_So;
            this.txtTai.Text = ThongTinDangKi.TK_Tai;
            this.txtOngBa.Text = ThongTinDangKi.DD_OngBa;
            this.txtChucVu.Text = ThongTinDangKi.DD_CV;
            //Ngay
            this.txtQuocTich.Text = ThongTinDangKi.DD_QuocTich;
            this.txtSoChungMinh.Text = ThongTinDangKi.DD_CMND;
            //Ngay
            this.txtNoiCapCMTND.Text = ThongTinDangKi.DD_NoiCap;
            this.txtNguoiLienHe.Text = ThongTinDangKi.DD_NguoiLH;
            this.txtDienThoaiLienHePL.Text = ThongTinDangKi.DD_DienThoai;
            this.txtTongSoNguoiThamGiaBH.Text = ThongTinDangKi.TongLD;
        }

        public void Ghi_01_DKBB()
        {            
                ThongTinDangKi.IDRef = IDref;
                ThongTinDangKi.KinhGui = this.txtBHXH.Text.ToString();
                ThongTinDangKi.TenDV = this.txtTenDonVi.Text.ToString();
                ThongTinDangKi.DiaChi = this.txtDiaChi.Text.ToString();
                ThongTinDangKi.DienThoai = this.txtDienThoai.Text.ToString();
                ThongTinDangKi.Email = this.txtDiaChiEmail.Text.ToString();
                ThongTinDangKi.Fax = this.txtFax.Text.ToString();
                ThongTinDangKi.CNDK_So = this.txtGiayPhepKDSo.Text.ToString();
                ThongTinDangKi.CNDK_Ngay = this.dateTimeNgayDKKD.Value.ToString();
                ThongTinDangKi.CNDK_Do = this.txtDoDonViCap.Text.ToString();
                ThongTinDangKi.LHDV = this.txtLoaiHinhDonVi.Text.ToString();
                ThongTinDangKi.MST = this.txtMaSoThue.Text.ToString();
                ThongTinDangKi.TK_So = this.txtTaiKhoanSo.Text.ToString();
                ThongTinDangKi.TK_Tai = this.txtTai.Text.ToString();
                ThongTinDangKi.DD_OngBa = this.txtOngBa.Text.ToString();
                ThongTinDangKi.DD_CV = this.txtChucVu.Text.ToString();
                ThongTinDangKi.DD_NgaySinh = this.dateTimeSinhNgay.Value.ToString();
                ThongTinDangKi.DD_QuocTich = this.txtQuocTich.Text.ToString();
                ThongTinDangKi.DD_CMND = this.txtSoChungMinh.Text.ToString();
                ThongTinDangKi.DD_NgayCap = this.dateTimeNgayCapCMTND.Value.ToString();
                ThongTinDangKi.DD_NoiCap = this.txtNoiCapCMTND.Text.ToString();
                ThongTinDangKi.DD_NguoiLH = this.txtNguoiLienHe.Text.ToString();
                ThongTinDangKi.DD_DienThoai = this.txtDienThoaiLienHePL.Text.ToString();
                ThongTinDangKi.TongLD = this.txtTongSoNguoiThamGiaBH.Text.ToString();
                
                if (lblID.Text != "0")
                {                   
                        _ttdkbh_dkbb01msSrv.UpDate_DangKi_Bao_Hiem(ThongTinDangKi);
                        MessageBox.Show(MainResource.msgCapNhatThanhCong, MainResource.textCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);                   
                }
                else
                {                   
                        _ttdkbh_dkbb01msSrv.Add_DangKi_Bao_Hiem(ThongTinDangKi);
                        MessageBox.Show(MainResource.msgLuuThanhCong, MainResource.textCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                  
                }
            
        }      

        public void NhapLai_01_DKBB() 
        { 
            Load_Data(ID, IDref);
        }          

    }
}
